home *** CD-ROM | disk | FTP | other *** search
- /*******************************<+>***************************
- ** DTA
- *************************************************************
- **
- ** $Id: main.C,v 1.8 1994/03/01 23:01:30 dta Exp $
- **
- ** $Source: /cvs/lib/odmg/test/main.C,v $
- **
- ** What @(#):
- **
- ** Author: Dale T. Anderson
- **
- *******************************<+>***************************/
-
- #include "Test.h"
-
- #include <Odmg/List.h>
- #include <Odmg/Array.h>
- #include <Odmg/Bag.h>
- #include <Odmg/Set.h>
-
- int verbose = 0;
-
- CTest::CTest (const int val)
- {
- //printf ("Construct CTest %d %x\n", val, this);
- m_val = val;
- }
-
- CTest::~CTest ()
- {
- //printf ("Destroy CTest %d %x\n", m_val, this);
- }
-
- void CTest::Print ()
- {
- print ("%d", m_val);
- }
-
- static void TestSet (Set <CTest> &set)
- {
- PrintInfo ("Set", set);
- }
-
- static void TestBag (Bag <CTest> &bag)
- {
- PrintInfo ("Bag", bag);
- }
-
- static void TestList (List <CTest> &list)
- {
- PrintInfo ("List", list);
- }
-
- static void TestArray (Varray <CTest> &array)
- {
- PrintInfo ("Array", array);
- }
-
- static void DeleteRef (Ref <ListNode <CTest> > ref)
- {
- delete (ListNode <CTest> *) ref;
- }
-
- static void TestListNode ()
- {
- const int count = 10;
-
- ListNode <CTest> list;
-
- for (int i = 0; i < count; i++)
- list.insert_node (new ListNode <CTest> (new CTest (i)));
-
- for (i = 0; i < count; i++) {
- delete (CTest *)(list.get_next_node ()->get_ref ());
- DeleteRef (list.get_next_node ());
- }
-
- for (i = 0; i < count; i++)
- list.append_node (new ListNode <CTest> (new CTest (i)));
-
- for (i = 0; i < count; i++) {
- delete (CTest *)(list.get_next_node ()->get_ref ());
- DeleteRef (list.get_next_node ());
- }
- }
-
- int main (int argc, char **argv)
- {
- extern int optopt;
- int err = 0;
- int c;
-
- while ((c = getopt (argc, argv, "v")) != -1) {
- switch (c) {
- case 'v':
- verbose++;
- break;
- case ':':
- fprintf (stderr, "Option -%c requires an argument\n", optopt);
- err++;
- break;
- case '?':
- fprintf (stderr, "Unrecognized option: - %c\n", optopt);
- err++;
- break;
- }
- }
-
- if (err) {
- fprintf (stderr, "Life is tough, life is tougher if you dont use -v\n");
- exit (1);
- }
-
- TestListNode ();
-
- Varray <CTest> array (0);
- TestCollection ("Array", array);
- TestArray (array);
-
- List <CTest> list;
- TestCollection ("List", list);
- TestList (list);
-
- Bag <CTest> bag;
- TestCollection ("Bag", bag);
- TestBag (bag);
-
- Set <CTest> set;
- TestCollection ("Set", set);
- TestSet (set);
-
- return 0;
- }
-
-